Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

194
Visualizações
Sound problem in "for" loop when Player win Javascript

Sound problem. In the "for" loop, a sound has been assigned when the car hits the hitbox of the package to be taken ('pacz'). This is counted as a point. Then the sound play: 'good'. Individually for each collected package. The problem arises when the player collects all 9 packs. The "good" sound then comes on many times at the same time. Is there any way to make the sound of the 9 pack sound 'good' play once at the end of the game?

    var root = this
    var collectedBoxes = 0
    root.mainPacz.gotoAndStop(boxArray[0])
    carCollisionSetup()
    boxCollisionSetup()
    var gameover = false
    function boxCollisionCheck() {
    let carBounds = root.car.getTransformedBounds();
    let infoBox = root.mainPacz
    for (i = 1; i < 10; i++) {
        let boxBounds = root['pacz' + i].getTransformedBounds()
        if (carBounds.intersects(boxBounds) && infoBox.timeline.position == root['pacz' + i].timeline.position) {
            takeAnim(root['pacz' + i])
            collectedBoxes++
            createjs.Sound.play('good')
            console.log('good w pacz')
            if (collectedBoxes < 9) {
                infoBox.gotoAndStop(boxArray[collectedBoxes])
                } else {
                if(!gameover)winFunction()
                console.log(winFunction)
                console.log('wrong pacz else')
            }
        } 
    }
    }
    function winFunction() {
    gameover = true
    console.log("=========WIN========")
    setTimeout (() =>{
        createjs.Sound.play('swietnie')
    },1500)
    setTimeout (() =>{
        root.play();
    },5000)
    stopCycle()
    root.stoper.play()
    //clearInterval(carPosChange)
    //timerTimeMS = 0
}
//ANCHOR Handling losing
function loseFunction() {
    console.log("=========LOSE========")
}

End of game with sounds looks like (These "consol.log" are called a lot of times.): enter image description here

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda